<?php

Yii::import('application.models._base.BaseAmanState');

class AmanState extends BaseAmanState {

    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    public static function label($n = 1) {
        return Yii::t('app', 'State|States', $n);
    }

    public function rules() {
        return array(
            array('state_name, status', 'length', 'max' => 45),
            array('state_name', 'unique'),
            array('state_name, status', 'default', 'setOnEmpty' => true, 'value' => null),
            array('id, state_name, status', 'safe', 'on' => 'search'),
        );
    }

    public static function getStates($stateId) {
        if (!empty($stateId)) {
            $state = AmanState::model()->findByPk($stateId);
            return $state->state_name;
        } else {
            return'';
        }
    }

    public static function listState() {

        $models = AmanState::model()->findAll(array("condition" => "status =  1"));

        // format models resulting using listData     
        $list = CHtml::listData($models, 'id', 'state_name');

        return $list;
    }

}